home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume11 / texpp / part01 next >
Encoding:
Text File  |  1990-03-25  |  41.7 KB  |  1,098 lines

  1. Newsgroups: comp.sources.misc
  2. From: csirmaz@poe.rutgers.edu
  3. Subject: v11i087: texpp - TeX preprocessor, 01/02
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 11, Issue 87
  7. Submitted-by: csirmaz@poe.rutgers.edu
  8. Archive-name: texpp/part01
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 1 (of 2)."
  17. # Contents:  MANIFEST README macro.pp tex-mode.el
  18. # Wrapped by allbery@uunet on Sun Mar 25 19:31:13 1990
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  22. else
  23. echo shar: Extracting \"'MANIFEST'\" \(269 characters\)
  24. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  25. X   File Name        Archive #    Description
  26. X-----------------------------------------------------------
  27. X MANIFEST                   1    This shipping list
  28. X README                     1    
  29. X macro.pp                   1    
  30. X tex-mode.el                1    
  31. X texpp.c                    2    
  32. END_OF_FILE
  33. if test 269 -ne `wc -c <'MANIFEST'`; then
  34.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  35. fi
  36. # end of 'MANIFEST'
  37. fi
  38. if test -f 'README' -a "${1}" != "-c" ; then 
  39.   echo shar: Will not clobber existing file \"'README'\"
  40. else
  41. echo shar: Extracting \"'README'\" \(14110 characters\)
  42. sed "s/^X//" >'README' <<'END_OF_FILE'
  43. X ***************************************************************************
  44. X *                                       *
  45. X *           texpp TeX preprocessor, Version 1.2.               *
  46. X *              Laci Csirmaz, DIMACS - Rutgers               *
  47. X *                   Feb. 25, 1990                   *
  48. X *                                       *
  49. X ***************************************************************************
  50. X *    You are granted to use, modify, copy, redistribute this program any  *
  51. X * way you want. However no warranties are made for this program or the    *
  52. X * accopanying documentation.                           *
  53. X *                                       *
  54. X *    Please send your comments, suggestions, etc. to:               *
  55. X *        csirmaz@cs.rutgers.edu                       *
  56. X *                                       *
  57. X ***************************************************************************
  58. X
  59. X
  60. X                       Tex Preprocessor  M A N U A L
  61. X
  62. X    0. Introduction
  63. X
  64. X    TeX, undoubtedly a very LOGICAL language, does not follow closely enough
  65. Xthe illogical nature of human beings. Using backslashes everywhere to signify
  66. Xa special treatment of a word is logical, but, of course, tedious and a bit
  67. Xboring. Whenever the word "alpha" appears in a text, with higher probability
  68. Xthan 0.9999 the author wishes the corresponding greek letter to appear, and
  69. Xnot this word. In the latter unlikely case, s/he is more willing to do some
  70. Xextra word to make the (now) exception the rule, and save a lot of work.
  71. X    Another drawback is the (also very logical, but unnatural) handling of
  72. Xmacros. If an operator is applied to a word (or a single letter), TeX
  73. Xrequires the operator to precede its argument. While in some cases this
  74. Xis the natural approach, in some cases it is not. As in using a dot, tilde, 
  75. Xor hat on a letter, the natural form is "x tilde", and not what is the
  76. Xobligatory form, "\tilde x".
  77. X    TeX forbids almost all key combinations to use as macro names, only
  78. Xsequences of letters are allowed. Why cannot I write "|==" instead of
  79. X"\model", "/0" for "\empty", or, horribile dictu, "/\" instead of "\wedge"?
  80. XFormulas written in this way are more readable, and easier to type.
  81. X    Finally, while TeX (and LaTeX) allows to redefine its macros, the user
  82. Xis usually not aware of its danger. Both plain TeX and LaTeX have a lot of
  83. Xbuilt-in macros which are absolutely necessary to run them. Redefining any
  84. Xof them the program simply goes crazy. And, in most of the cases, the user
  85. Xdoes not even know why the construct is wrong. What happens, for example, 
  86. Xif "\and" is redefined in LaTeX so that it would produce the sign /\ -- a 
  87. Xquite reasonable assumption. To avoid all the problems arising this way, TeX 
  88. Xshould do these definitions locally, which it doesn't.
  89. X
  90. X    All of the above problems lead to the development of the "texpp" TeX
  91. Xpreprocessor. Since TeX is quite ambivalent about handling the input layout
  92. X(often it says to be independent of whitespaces, but two consecutive newlines
  93. Xsignify a new paragraph, and comments are closed by newlines), I decided to
  94. Xuse layout a bit more significantly than TeX does. All macro definitions
  95. Xshould start at the first column. The preprocessor is not intended to be as
  96. Xgeneral as possible. It has a lot of wired in features (for example, the $ 
  97. Xand $$ to start and end math mode), but the C code is available, and (at 
  98. Xleast I hope) can be modified easily. Also, the preprocessor is absolutely 
  99. XNOT for TeX wizards. It can be fooled quite easily e.g. by redefining the
  100. Xescape character, but as far as it is used as a simple tool it works fine.
  101. X
  102. X
  103. X    1. Shipped files
  104. X
  105. X    Besides the C source code of the program and this manual, you can find
  106. Xa sample macro file which show some extra features of texpp. Also I wrote
  107. Xa tex-mode.el (gnu)emacs template which embeds the 'texpp' preprocessor, and
  108. Xa dvi viewer.
  109. X    The program was written for UNIX(TM) machines, but the code is highly
  110. Xportable (at least I hope so). Therefore it should be easy yo transport to
  111. Xother machines.
  112. X              
  113. X
  114. X    2. Macro names
  115. X
  116. X    Macro name can be any sequence of characters which does not contain
  117. Xbraces `{' and `}', dollar sign `$', percentage sign `%', and embedded
  118. Xwhitespaces. `Character' here means a character with ASCII code >=32 and
  119. X<= 126. Each line of the text is cut at braces and whitespaces, and what
  120. Xis left is compared against the list of macro names. If there is a hit, then
  121. Xthe closing braces or white spaces are erased, and the macro text is replaced.
  122. X
  123. X    3. Parameters
  124. X
  125. X    A macro may have up to nine parameters, which can be either before or
  126. Xafter the macro name. Parameters are parsed starting from the macro name:
  127. Xeach parameter is either enclosed into braces, or contains no braces and is
  128. Xenclosed by whitespaces. A parameter must have balanced braces, if any.
  129. XIn braces, it may have embedded white spaces. Parameters may contain further
  130. Xmacro names, too, but parameter parsing is done BEFORE macro substitution.
  131. XTwo macros cannot share parameters. A parameter is always stripped off its
  132. Xenclosing characters, and then a macro substitution is executed on it. A
  133. Xparameter can be a macro name with further parameters (see the examples).
  134. XIf the macro name is enclosed into braces, all its parameters must also be
  135. Xinside.
  136. X
  137. X
  138. X    4. Macro definition
  139. X
  140. X    Macros can be defined anywhere. A definition always starts at the first 
  141. Xcharacter of the line, and signified by the key words `%define' or `%mdefine'. 
  142. X(Starting with percentage sign, but NO BACKSLASH is here). The form of a
  143. Xdefinition is the following:
  144. X
  145. X    %define <preceeding pars> name <follow up pars>  %text% <any comment>
  146. X
  147. XLocal parameters are of the form #1, #2, ..., #9. No parameters are required,
  148. Xthey can appear in any order and in any place. The REPLACEMENT text is enclosed
  149. Xby `%' characters (thus it cannot contain `%', but of course it may contain
  150. Xthe `\%' pair!), and is used as it is, with the following exeptions:
  151. X
  152. X    a) local parameters #1, ... #9 are replaced by the stripped and 
  153. X       expanded parameters of the invocation;
  154. X    b) the pair ## is replaced by a single # mark.
  155. X    c) macro calls are expanded.
  156. X
  157. XRule b) also applies to the macro name. Thus `#' can also appear in a macro
  158. Xname, but should be written as `##'. (Of course, when looking for a macro name
  159. Xin the text, this corresponds to the single character!)
  160. X    Macro definitions starting by `%mdefine' are applied only when in math
  161. Xor displayed math mode; other definitions are always applicable. The program
  162. Xassumes that the macro body does not switch these modes.
  163. X    Besides defining macros, you can "undefine" them, too. This comes handy
  164. Xwhen a macro is used only as an auxiliary in a more complicated definition, 
  165. Xbut not needed later. A new definition "hides" the old one, undefining
  166. Xrestores the old meaning. This can be done by
  167. X
  168. X    %undefine name
  169. Xor
  170. X    %undefine name % <your comment here>
  171. X
  172. XIt is an error to undefine a macro which was not defined (or mdefined)
  173. Xbefore.
  174. X
  175. X    5. Auxiliary tools
  176. X
  177. X    In certain cases it is essential to suppress macro substitution. This
  178. Xcan be done by applying the `\preserve' keyword to its single parameter:
  179. X
  180. X    \preserve <anything_which_does_not_contain_whitespace_or_brace>
  181. Xor
  182. X    \preserve {<any text with balanced braces>}
  183. X
  184. XIn the parameter to `\preserve' no macro substitution is made. However, 
  185. X`\preserve' cannot be applied to macro parameters in macro definitions, 
  186. Xsince parameter expansion is done BEFORE substitution.
  187. X
  188. X    Different extensions of TeX use different macros to switch to and from 
  189. Xmath mode. To comply with them, the following definitions are recognized:
  190. X
  191. X    %mathmode <string_to_enter_math_mode>  <string_leave_math_mode>
  192. Xand
  193. X    %dispmode <string_to_enter_displayed_math>  <string_leaving>
  194. X
  195. XThe strings cannot contain white spaces, and if only one string is given in
  196. Xa definition, then that is used for both entering and leaving math mode. 
  197. XIn LaTeX the following definitions may come handy:
  198. X
  199. X    %mathmode \( \)            %simple math mode
  200. X    %mathmode \math \endmath
  201. X    %dispmode \[ \]            %displayed formulas
  202. X    %dispmode \equation \endequation    %for numbered formulas
  203. X
  204. X
  205. X    6. Examples
  206. X
  207. Xo 6.1. The first example defines the `*16' macro, which repeats its argument
  208. X sixteen times:
  209. X
  210. X %define #1 *2 %#1#1%        %define `*2' as an auxiliary macro
  211. X %define #1 *16 %#1 *2 *2 *2 *2%
  212. X %undefine *2            %undefine `*2', no more needed
  213. X
  214. X Texts `x 1 *16 y' and `x{1}*16 y' expand to `x1111111111111111y'. (Observe
  215. X that the trailing space after `*16' vanished). At the same time `x 1*16 y'
  216. X and `x 1 *16y' remain unchanged since the macro name `*16' cannot be
  217. X extracted.  As another example, `x {a b} *16 y' saves the space between `a'
  218. X and `b', and before the open brace but not after the macro name. So the
  219. X result is
  220. X
  221. X    `x a ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba by'
  222. X
  223. X
  224. Xo 6.2. The next example also shows that macro definitions are expanded when
  225. X defined, and not when invoked. This means, for example, that subsequent
  226. X macro definitions have no influence on an existing macro definition. This
  227. X fact is used here:
  228. X
  229. X %define [[  %[%    define [[ as a macro to be substituted by [
  230. X %define ]]  %]%    define ]] as a macro to be substituted by ]
  231. X %define [   %\{%    now define [ to mean \{
  232. X %define ]   %\}%    and define ] to mean \}
  233. X
  234. X The last two definitions make a text like
  235. X
  236. X    a = [ 0, 1, 2, ..., n ] + [ 2n, ..., 4n ]
  237. X
  238. X to transform to
  239. X
  240. X    a =\{0, 1, 2, ..., n\}+\{2n, ..., 4n\}
  241. X
  242. X while, e.g. a reference can be put into square brackets by using double
  243. X brackets: ` [[ 1 ]] ' which becomes `[1]'. Changing the last two and first 
  244. X two definitions here, the definition of `[[' becomes identical to that of 
  245. X `[', i.e. with `\{'.
  246. X
  247. X
  248. Xo 6.3. Our third example defines some model-theoretical stuff:
  249. X
  250. X %mdefine /\   % \wedge %           and sign
  251. X %mdefine \/   % \vee %             or sign
  252. X %mdefine |--  % \vdash %           syntactically follows
  253. X %mdefine |==  % \models %          semantically follows
  254. X %mdefine -->  % \rightarrow %       implies
  255. X %mdefine phi  % \varphi %
  256. X %mdefine ALL  % \forall %
  257. X %mdefine not  % \neg %             
  258. X %mdefine ...  % \ldots %           ellipsis notation
  259. X
  260. X Since the preprocessor does not treat the backslash as a special symbol,
  261. X `/\' and `\/' will be recognized without any trouble. The spaces at the 
  262. X end of each definition are necessary because before replacing the macro 
  263. X name, its surrounding white spaces (or braces) are deleted. So displayed
  264. X formulas can be written as, e.g.
  265. X
  266. X    $$ |== ALL x ( phi (x) \/ not phi (x) ) $$
  267. X    $$ |-- phi --> ( not phi --> phi ) $$
  268. X
  269. X
  270. Xo 6.4. Sometimes it is convenient to use `**' to denote exponentiation:
  271. X
  272. X %mdefine #1 ** #2 %#1^{#2}%
  273. X
  274. X Here ` e ** { x ** 2 / 2 } ' or ` e **{x ** 2 /2}' becomes `e^{x^{2}/ 2 } '
  275. X (look out for the spaces!). The braces around #2 in the definition are
  276. X necessary to ensure that all the second parameter shows up in the exponent.
  277. X Without those braces the expanded form of the first form would be
  278. X `e^x^2/ 2 ', evidently not what was intended.
  279. X
  280. X
  281. Xo 6.5. The next example shows how to use "before" parameters when they are
  282. X handy:
  283. X
  284. X %mdefine #1 tilde %\wildetilde{#1}%
  285. X %mdefine #1 hat %\wildehat{#1}%
  286. X
  287. X After these definition the following text
  288. X    ...
  289. X    a+b tilde = a tilde + b tilde
  290. X    ...
  291. X expands to
  292. X    ...
  293. X    \wildetilde{a+b}=\wildetilde{a}+\wildetilde{b}
  294. X    ...
  295. X Which one is easier to read?
  296. X
  297. X
  298. Xo 6.6. To overcome the problem corresponding to greek letters, one can define
  299. X
  300. X %define alpha %$\alpha$%
  301. X
  302. X (since greek letters are allowed in math mode only.) With this definition, 
  303. X however, there are certain problems. Using this macro in the text `Let alpha 
  304. X be the ...', the substitution mechanism erases ALL the spaces around the word 
  305. X `alpha', and the result is `Let$\alpha$be the ...'. Evidently no what was 
  306. X wanted. Changing the definition to
  307. X
  308. X %define alpha % $\alpha$ % now with spaces
  309. X
  310. X will put back the spaces both BEFORE and AFTER the word, thus giving 
  311. X    Let $\alpha$ be the ...
  312. X       ^^^^^^^^^^-- substituted text
  313. X Having this latter definition, however, you cannot write alpha's without 
  314. X intervening spaces. Another problem is that this definition cannot be used in 
  315. X math mode! A possible solution is that the macro `alpha' will be used in math 
  316. X mode only, now with the definition
  317. X
  318. X %mdefine alpha %\alpha %
  319. X
  320. X The above sentence can be written as `Let $alpha$ be the ...'. Also, two
  321. X consecutive alpha's can be produced as
  322. X
  323. X    `here are two $alpha$'s: $alpha alpha$'.
  324. X
  325. X The word alpha, if found not in math mode, won't change. And, if you want
  326. X to use the word alpha in math (or displayed) mode, you can use the \preserve
  327. X keyword:
  328. X    I can write $\preserve alpha$ in math mode.
  329. X
  330. X
  331. Xo 6.7. Strings used to switch to and from math mode are also subject to macro
  332. X replacement. Thus using the definitions
  333. X
  334. X \def\mydisplayformula#1#2{ $$ #2 \leqno #1 $$}
  335. X %dispmode .EQ .EN
  336. X %define .EQ #1 % \mydisplayformula{#1}{ %
  337. X %define .EN % } %
  338. X
  339. X an eqn-like construct for display formulas can be used so that the formula
  340. X number (written after .EQ) appears on the left of the displayed formula.
  341. X However, if you don't want this number to appear, you still have to submit
  342. X a parameter, which can be the empty string, i.e. `{}'
  343. X
  344. X
  345. X   7. How to use the preprocessor?
  346. X
  347. XTo compile the program on a UNIX machine, simply invoke cc by typing
  348. X
  349. X        cc texpp.c -o texpp
  350. X
  351. XOn certain systems the 'strdup()' function is missing from the standard C
  352. Xlibrary. In this case, recompile the program by
  353. X
  354. X        cc -DSTRDUP texpp.c -o texpp
  355. X
  356. XThe preprocessor works as a filter. It reads one ore more input files,
  357. Xprocesses them, and then produces a single output which can be the input
  358. Xfor TeX. The program can be invoked by typing
  359. X
  360. X    texpp file1 file2 ... filen -[wa] output_file 
  361. X
  362. X`file1', ..., `filen' are processed in their given order; a file definition
  363. Xconsisting of a single `-' sign means read from stdin. The output goes to 
  364. X`output_file', the file is overwritten if the name is preceded by `-w', and
  365. Xis appended if `-a' is present. Error messages are inserted into the output
  366. Xand are duplicated at stderr. If no input file is given, the program reads
  367. Xfrom stdin; if no output file is given, then the output goes to stdout. When
  368. Xthe program halts, the exit value is 0 if `texpp' run successfully, if any
  369. Xerror occurred (cannot open a file or processing error) then the exit value
  370. Xis 1.
  371. X
  372. END_OF_FILE
  373. if test 14110 -ne `wc -c <'README'`; then
  374.     echo shar: \"'README'\" unpacked with wrong size!
  375. fi
  376. # end of 'README'
  377. fi
  378. if test -f 'macro.pp' -a "${1}" != "-c" ; then 
  379.   echo shar: Will not clobber existing file \"'macro.pp'\"
  380. else
  381. echo shar: Extracting \"'macro.pp'\" \(4392 characters\)
  382. sed "s/^X//" >'macro.pp' <<'END_OF_FILE'
  383. X%% ---- TeXpp macro definitions ----
  384. X%% ----   for plain TeX files   ----
  385. X%%
  386. X%%  A macro definition should fit into a single line. If the definition is 
  387. X%%  too long, we can continue after closing the line with a backslash....
  388. X%%
  389. X%% - 1.   Greek letters  ----
  390. X%mdefine alpha        %\alpha %
  391. X%mdefine beta        %\beta %
  392. X%mdefine gamma        %\gamma %
  393. X%mdefine delta        %\delta %
  394. X%mdefine eps        %\varepsilon %
  395. X%mdefine zeta        %\zeta %
  396. X%mdefine eta        %\eta %
  397. X%mdefine theta        %\vartheta %
  398. X%mdefine iota        %\iota %
  399. X%mdefine kappa        %\kappa %
  400. X%mdefine pi        %\pi %
  401. X%mdefine rho        %\varrho %
  402. X%mdefine chi        %\chi %
  403. X%mdefine phi        %\varphi %
  404. X%mdefine psi        %\psi %
  405. X%mdefine omega        %\omega %
  406. X%mdefine GAMMA        %\Gamma %
  407. X%mdefine DELTA        %\Delta %
  408. X%mdefine LAMBDA        %\Lambda %
  409. X%mdefine PHI        %\Phi %
  410. X%mdefine SIGMA        %\Sigma %
  411. X%%
  412. X%% -2.   Mathematical functions names ----
  413. X%mdefine log        %\log %
  414. X%mdefine sin        %\sin %
  415. X%mdefine cos        %\cos %
  416. X%mdefine mod        %\bmod %        as in "i mod 2"
  417. X%%
  418. X%% -3.   Special symbols ----
  419. X%mdefine aleph        %\aleph %
  420. X%mdefine l        %\ell %            written letter
  421. X%mdefine ||        %\|%            norm sign
  422. X%mdefine oo        %\infty %        infinity
  423. X%mdefine not        %\neg %            negation sign
  424. X%mdefine EMPTY        %\emptyset %        slashed zero
  425. X%mdefine o|o        %\clubsuit %
  426. X%mdefine <>        %\diamondsuit %
  427. X%%
  428. X%%        doubly written C,N,Q and R letters for
  429. X%%        complex, natural, rational and real numbers
  430. X%mdefine IC        %\hbox{\hbox{C\hskip-0.5em\lower-0.1ex\
  431. X           \hbox{\vrule height1.34ex width0.07em }}\hskip0.50em}%
  432. X
  433. X%mdefine IN        %\hbox{I\hskip-0.20em I\hskip-0.35em N}%
  434. X%mdefine IQ        %\hbox{\hbox{Q\hskip-0.525em\lower-0.097ex\
  435. X            \hbox{\vrule height1.47ex width0.07em}}\hskip0.50em}%
  436. X%mdefine IR        %\hbox{I\hskip-0.23em R}%
  437. X%%
  438. X%%        I don't like these thin signs, so I redefined them
  439. X%%mdefine ALL #1    %\forall #1 \>%
  440. X%%mdefine EXISTS #1    %\exists #1 \>%
  441. X%mdefine ALL #1        %{\leavevmode\hbox{\rm V\kern-0.53em\
  442. X\lower-.5ex\hbox{-}}\kern0.1em} #1 \>%
  443. X%mdefine EXISTS #1    %{\Xi\kern-0.37em{\bf I}} #1 \>%
  444. X%%
  445. X%% -4.   Operators ----
  446. X%mdefine /\        %\wedge %        and sign
  447. X%mdefine _/\_         %\bigwedge%        big and sign
  448. X%mdefine \/        %\vee %            or sign
  449. X%mdefine ~\/~        %\bigvee %        big or sign
  450. X%mdefine +-        %\pm %            plusminus
  451. X%mdefine COMP        %\circ %        small circle (composition)
  452. X%mdefine CROSS        %\times %        cross for vectors
  453. X%mdefine BULL        %\bullet %        full small circle
  454. X%mdefine dot        %\cdot %        centered dot (multiplication)
  455. X%mdefine UNION        %\cup %            small union symbol
  456. X%mdefine METS        %\cap %            small intersection symbol
  457. X%%                        +/-/= sign and a dot on it
  458. X%mdefine .+.        %{\mathrel{\> +\hbox{\hskip-0.565em\
  459. X\lower-1.8ex\hbox{.}}\hskip0.4em}}%
  460. X%mdefine .-.        %{\mathrel{\> -\hbox{\hskip-0.55em\
  461. X\lower-1.2ex\hbox{.}}\hskip0.4em}}%
  462. X%mdefine .=.        %\doteq %
  463. X%%
  464. X%% -5.   Relations ----
  465. X%mdefine ==        %\equiv %        equivalence
  466. X%mdefine !==        %\not\equiv %        slashed equivalence
  467. X%mdefine !=        %\not= %        not equal
  468. X%mdefine <=        %\leq %            less than or equal to
  469. X%mdefine >=        %\geq %
  470. X%mdefine SUBS        %\subset %        subset of
  471. X%mdefine EXTS        %\supset %        extension of
  472. X%mdefine in        %\in %            element
  473. X%mdefine !in        %\notin% %        not an element
  474. X%mdefine |--        %\vdash %        proves
  475. X%mdefine !|--        %\not\vdash %        not proves
  476. X%mdefine |==        %\models %        semantically follows
  477. X%mdefine !|==        %\not\models %
  478. X%%
  479. X%% -6.   Arrows ----
  480. X%mdefine -->        %\rightarrow %
  481. X%mdefine <-->        %\leftrightarrow %
  482. X%mdefine <--        %\leftarrow %
  483. X%mdefine ==>        %\Rightarrow %
  484. X%mdefine <==>        %\Leftrightarrow %
  485. X%mdefine ==>        %\Rightarrow %
  486. X%mdefine |-->        %\mapsto %
  487. X%%
  488. X%% -7.   Miscellaneous ----
  489. X%mdefine ...        %\ldots %        ellipsis
  490. X%mdefine ...,        %\ldots,%        dots followed by a comma
  491. X%mdefine =def        % \>{\buildrel \rm def \over =}\> %
  492. X%mdefine <:        %\langle %        left angular bracket
  493. X%mdefine :>        %\rangle %        right angular bracket
  494. X%mdefine [[        %[\![%            double open [
  495. X%mdefine ]]        %]\!]%            double closing ]
  496. X%%
  497. X%mdefine #1 tilde    %\widetilde{#1}%    put a tilde 
  498. X%mdefine #1 bar        %\overline{#1}%        put a line over
  499. X%mdefine #1 hat        %\wildehat{#1}%        put a hat (^)
  500. X%mdefine #1 vec        %\overrightarrow{#1}%    put a --> at the top
  501. X%mdefine sub #1        %_{#1}%            for a subscript
  502. X%mdefine sup #1        %^{#1}%            for a superscript
  503. X%%
  504. X\def\mydisplayformula#1#2{ $$ #2 \leqno #1 $$}
  505. X%define .EQ #1        %\mydisplayformula{#1}{%
  506. X%define .EN        %}%
  507. X%dispmode .EQ .EN
  508. X%%
  509. X%define LEMMA #1    %\proclaim Lemma #1 %
  510. X%define PROOF.        %\noindent{\bf Proof.} %
  511. X%define THEOREM #1    %\proclaim Theorem #1 %
  512. X%define QED        % {\vrule height 7pt depth 1pt width 7pt} % back box
  513. X%mdefine iff        %{\ \ \rm iff \ \ }%
  514. X
  515. X
  516. END_OF_FILE
  517. if test 4392 -ne `wc -c <'macro.pp'`; then
  518.     echo shar: \"'macro.pp'\" unpacked with wrong size!
  519. fi
  520. # end of 'macro.pp'
  521. fi
  522. if test -f 'tex-mode.el' -a "${1}" != "-c" ; then 
  523.   echo shar: Will not clobber existing file \"'tex-mode.el'\"
  524. else
  525. echo shar: Extracting \"'tex-mode.el'\" \(20255 characters\)
  526. sed "s/^X//" >'tex-mode.el' <<'END_OF_FILE'
  527. X;; TeX mode commands.
  528. X;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
  529. X;; Rewritten following contributions by William F. Schelter
  530. X;; and Dick King (king@kestrel).
  531. X;; Modified August 1986 by Stephen Gildea <mit-erl!gildea> and
  532. X;; Michael Prange <mit-erl!prange> to add LaTeX support and enhance
  533. X;; TeX-region.
  534. X;; Added TeX-directory and reorganized somewhat  gildea 21 Nov 86
  535. X;; Modified to handle TeX preprocessors by csirmaz@cs.rutgers.edu 21 Nov 89
  536. X
  537. X;; This file is part of GNU Emacs.
  538. X
  539. X;; GNU Emacs is distributed in the hope that it will be useful,
  540. X;; but WITHOUT ANY WARRANTY.  No author or distributor
  541. X;; accepts responsibility to anyone for the consequences of using it
  542. X;; or for whether it serves any particular purpose or works at all,
  543. X;; unless he says so in writing.  Refer to the GNU Emacs General Public
  544. X;; License for full details.
  545. X
  546. X;; Everyone is granted permission to copy, modify and redistribute
  547. X;; GNU Emacs, but only under the conditions described in the
  548. X;; GNU Emacs General Public License.   A copy of this license is
  549. X;; supposed to have been given to you along with GNU Emacs so you
  550. X;; can know your rights and responsibilities.  It should be in a
  551. X;; file named COPYING.  Among other things, the copyright notice
  552. X;; and this notice must be preserved on all copies.
  553. X
  554. X;; Still to do:
  555. X;;  Make TAB indent correctly for TeX code.  Then we can make linefeed
  556. X;;  do something more useful.
  557. X;;
  558. X;;  Have spell understand TeX instead of assuming the entire world
  559. X;;  uses nroff.
  560. X;;
  561. X;;  The code for finding matching $ needs to be fixed.
  562. X
  563. X;;;
  564. X;;; To costumize TeX preprocessing, you can put the following lines
  565. X;;; into the .emacs init file:
  566. X;;;    (defun set-my-TeX-filter-default ()
  567. X;;;      (setq TeX-show-dvi-command "your favorite DVI view program")
  568. X;;;      (setq TeX-filter "...here the filter with full path...")
  569. X;;;      (setq TeX-filter-args '("...first macro file with full path..." 
  570. X;;;                              "...second macro file with full path..."
  571. X;;;                              "-"     ;;;for the buffer
  572. X;;;                              "-a"))  ;;;append the output
  573. X;;;    )
  574. X;;;    (setq TeX-mode-hook (if (boundp 'TeX-mode-hook)
  575. X;;;       (append TeX-mode-hook 'set-my-TeX-filter-default)
  576. X;;;       'set-my-TeX-filter-default)
  577. X;;;    )
  578. X;;; If you want to use 'ispell' to check TeX text, use the following in
  579. X;;; your .emacs init file:
  580. X;;;    (require 'ispell)
  581. X;;;    (set-default 'ispell-filter-hook shell-file-name)
  582. X;;;    (set-default 'ispell-filter-hook-args 
  583. X;;;                 '("-f" "-c" "(detex -iw | tr -cs A-Za-z \\\\012)"))
  584. X
  585. X
  586. X;;;
  587. X
  588. X(provide 'tex-mode)
  589. X
  590. X(defvar TeX-directory "/tmp/"
  591. X  "*Directory in which to run TeX subjob.  Temporary files are
  592. Xcreated in this directory.")
  593. X(defvar TeX-dvi-print-command "lpr -d"
  594. X  "*Command string used by \\[TeX-print] to print a .dvi file.")
  595. X(defvar TeX-show-dvi-command "texx"
  596. X  "*Command used by \\[TeX-view-dvi] for screen view the dvi file")
  597. X(defvar TeX-show-queue-command "lpq"
  598. X  "*Command string used by \\[TeX-show-print-queue] to show the print queue
  599. Xthat \\[TeX-print] put your job on.")
  600. X(defvar TeX-default-mode 'plain-TeX-mode
  601. X  "*Mode to enter for a new file when it can't be determined whether
  602. Xthe file is plain TeX or LaTeX or what.")
  603. X
  604. X(defvar TeX-command nil
  605. X  "The command to run TeX on a file.  The name of the file will be appended
  606. Xto this string, separated by a space.")
  607. X(defvar TeX-filter ()
  608. X  "*Filter to produce a file by \\[TeX-region] on which TeX is called.")
  609. X(defvar TeX-filter-args '()
  610. X  "*Arguments to the filter TeX-filter")
  611. X(defvar TeX-trailer nil
  612. X  "String appended after the end of a region send to TeX by \\[TeX-region].")
  613. X(defvar TeX-start-of-header nil
  614. X  "String used by \\[TeX-region] to delimit the start of the file's header.")
  615. X(defvar TeX-end-of-header nil
  616. X  "String used by \\[TeX-region] to delimit the end of the file's header.")
  617. X(defvar TeX-shell-cd-command "cd"
  618. X  "Command to give to shell running TeX to change directory.  The value of
  619. XTeX-directory will be appended to this, separated by a space.")
  620. X(defvar TeX-zap-file nil
  621. X  "Temporary file name used for text being sent as input to TeX.
  622. XShould be a simple file name with no extension or directory specification.")
  623. X
  624. X(defvar TeX-mode-syntax-table nil
  625. X  "Syntax table used while in TeX mode.")
  626. X
  627. X(defun TeX-define-common-keys (keymap)
  628. X  "Define the keys that we want defined both in TeX-mode
  629. Xand in the TeX-shell."
  630. X  (define-key keymap "\C-c\C-k" 'TeX-kill-job)
  631. X  (define-key keymap "\C-c\C-l" 'TeX-recenter-output-buffer)
  632. X  (define-key keymap "\C-c\C-q" 'TeX-show-print-queue)
  633. X  (define-key keymap "\C-c\C-p" 'TeX-print)
  634. X  (define-key keymap "\C-c\C-v" 'TeX-view-dvi)
  635. X  )
  636. X
  637. X(defvar TeX-mode-map nil "Keymap for TeX mode")
  638. X
  639. X(if TeX-mode-map 
  640. X    nil
  641. X  (setq TeX-mode-map (make-sparse-keymap))
  642. X  (TeX-define-common-keys TeX-mode-map)
  643. X  (define-key TeX-mode-map "\"" 'TeX-insert-quote)
  644. X  (define-key TeX-mode-map "\n" 'TeX-terminate-paragraph)
  645. X  (define-key TeX-mode-map "\e}" 'up-list)
  646. X  (define-key TeX-mode-map "\e{" 'TeX-insert-braces)
  647. X  (define-key TeX-mode-map "\C-c\C-r" 'TeX-region)
  648. X  (define-key TeX-mode-map "\C-c\C-b" 'TeX-buffer)
  649. X  (define-key TeX-mode-map "\C-c\C-f" 'TeX-close-LaTeX-block)
  650. X  )
  651. X
  652. X(defvar TeX-shell-map nil
  653. X  "Keymap for the TeX shell.  A shell-mode-map with a few additions")
  654. X
  655. X;(fset 'TeX-mode 'tex-mode)         ;in loaddefs.
  656. X
  657. X;;; This would be a lot simpler if we just used a regexp search,
  658. X;;; but then it would be too slow.
  659. X(defun tex-mode ()
  660. X  "Major mode for editing files of input for TeX or LaTeX.
  661. XTrys to intuit whether this file is for plain TeX or LaTeX and
  662. Xcalls plain-tex-mode or latex-mode.  If it cannot be determined
  663. X\(e.g., there are no commands in the file), the value of
  664. XTeX-default-mode is used."
  665. X  (interactive)
  666. X  (let (mode slash comment)
  667. X    (save-excursion
  668. X      (goto-char (point-min))
  669. X      (while (and (setq slash (search-forward "\\" nil t))
  670. X          (setq comment (let ((search-end (point)))
  671. X                  (save-excursion
  672. X                    (beginning-of-line)
  673. X                    (search-forward "%" search-end t))))))
  674. X      (if (and slash (not comment))
  675. X      (setq mode (if (looking-at "documentstyle")
  676. X             'latex-mode
  677. X               'plain-tex-mode))))
  678. X    (if mode (funcall mode)
  679. X      (funcall TeX-default-mode))))
  680. X
  681. X(fset 'plain-TeX-mode 'plain-tex-mode)
  682. X(fset 'LaTeX-mode 'latex-mode)
  683. X
  684. X(defun plain-tex-mode ()
  685. X  "Major mode for editing files of input for plain TeX.
  686. XMakes $ and } display the characters they match.
  687. XMakes \" insert `` when it seems to be the beginning of a quotation,
  688. Xand '' when it appears to be the end; it inserts \" only after a \\.
  689. X
  690. XUse \\[TeX-region] to run TeX on the current region, plus a \"header\"
  691. Xcopied from the top of the file (containing macro definitions, etc.),
  692. Xrunning TeX under a special subshell.  \\[TeX-buffer] does the whole buffer.
  693. X\\[TeX-print] prints the .dvi file made by either of these,
  694. X\\[TeX-view-dvi] shows a dvi view.
  695. X
  696. XUse \\[validate-TeX-buffer] to check buffer for paragraphs containing
  697. Xmismatched $'s or braces.
  698. X
  699. XSpecial commands:
  700. X\\{TeX-mode-map}
  701. X
  702. XMode variables:
  703. XTeX-directory
  704. X    Directory in which to create temporary files for TeX jobs
  705. X    run by \\[TeX-region] or \\[TeX-buffer].
  706. XTeX-filter
  707. X    program (maybe with full path) to filter the region or buffer
  708. X    before calling tex or latex.
  709. XTeX-filter-args
  710. X    list of arguments to TeX-filter.
  711. XTeX-dvi-print-command
  712. X    Command string used by \\[TeX-print] to print a .dvi file.
  713. XTeX-show-queue-command
  714. X    Command string used by \\[TeX-show-print-queue] to show the print
  715. X    queue that \\[TeX-print] put your job on.
  716. X
  717. XEntering plain-TeX mode calls the value of text-mode-hook,
  718. Xthen the value of TeX-mode-hook, and then the value
  719. Xof plain-TeX-mode-hook."
  720. X  (interactive)
  721. X  (TeX-common-initialization)
  722. X  (setq mode-name "TeX")
  723. X  (setq major-mode 'plain-TeX-mode)
  724. X  (setq TeX-command "tex")
  725. X  (setq TeX-start-of-header "%**start of header")
  726. X  (setq TeX-end-of-header "%**end of header")
  727. X  (setq TeX-trailer "\\bye\n")
  728. X  (run-hooks 'text-mode-hook 'TeX-mode-hook 'plain-TeX-mode-hook))
  729. X
  730. X(defun latex-mode ()
  731. X  "Major mode for editing files of input for LaTeX.
  732. XMakes $ and } display the characters they match.
  733. XMakes \" insert `` when it seems to be the beginning of a quotation,
  734. Xand '' when it appears to be the end; it inserts \" only after a \\.
  735. X
  736. XUse \\[TeX-region] to run LaTeX on the current region, plus the preamble
  737. Xcopied from the top of the file (containing \\documentstyle, etc.),
  738. Xrunning LaTeX under a special subshell.  \\[TeX-buffer] does the whole buffer.
  739. X\\[TeX-print] prints the .dvi file made by either of these.
  740. X
  741. XUse \\[validate-TeX-buffer] to check buffer for paragraphs containing
  742. Xmismatched $'s or braces.
  743. X
  744. XSpecial commands:
  745. X\\{TeX-mode-map}
  746. X
  747. XMode variables:
  748. XTeX-directory
  749. X    Directory in which to create temporary files for TeX jobs
  750. X    run by \\[TeX-region] or \\[TeX-buffer].
  751. XTeX-filter
  752. X    program (maybe with full path) to filter the region or buffer
  753. X    before calling tex or latex.
  754. XTeX-filter-args
  755. X    list of arguments to TeX-filter.
  756. XTeX-dvi-print-command
  757. X    Command string used by \\[TeX-print] to print a .dvi file.
  758. XTeX-show-queue-command
  759. X    Command string used by \\[TeX-show-print-queue] to show the print
  760. X    queue that \\[TeX-print] put your job on.
  761. X
  762. XEntering LaTeX mode calls the value of text-mode-hook,
  763. Xthen the value of TeX-mode-hook, and then the value
  764. Xof LaTeX-mode-hook."
  765. X  (interactive)
  766. X  (TeX-common-initialization)
  767. X  (setq mode-name "LaTeX")
  768. X  (setq major-mode 'LaTeX-mode)
  769. X  (setq TeX-command "latex")
  770. X  (setq TeX-start-of-header "\\documentstyle")
  771. X  (setq TeX-end-of-header "\\begin{document}")
  772. X  (setq TeX-trailer "\\end{document}\n")
  773. X  (run-hooks 'text-mode-hook 'TeX-mode-hook 'LaTeX-mode-hook))
  774. X
  775. X(defun TeX-common-initialization ()
  776. X  (kill-all-local-variables)
  777. X  (use-local-map TeX-mode-map)
  778. X  (setq local-abbrev-table text-mode-abbrev-table)
  779. X  (if (null TeX-mode-syntax-table)
  780. X      (progn
  781. X    (setq TeX-mode-syntax-table (make-syntax-table))
  782. X    (set-syntax-table TeX-mode-syntax-table)
  783. X    (modify-syntax-entry ?\\ ".")
  784. X    (modify-syntax-entry ?\f ">")
  785. X    (modify-syntax-entry ?\n ">")
  786. X    (modify-syntax-entry ?$ "$$")
  787. X    (modify-syntax-entry ?% "<")
  788. X    (modify-syntax-entry ?\" ".")
  789. X    (modify-syntax-entry ?& ".")
  790. X    (modify-syntax-entry ?_ ".")
  791. X    (modify-syntax-entry ?@ "_")
  792. X    (modify-syntax-entry ?~ " ")
  793. X    (modify-syntax-entry ?' "w"))
  794. X    (set-syntax-table TeX-mode-syntax-table))
  795. X  (make-local-variable 'paragraph-start)
  796. X  (setq paragraph-start "^[ \t]*$\\|^[\f\\\\]")
  797. X  (make-local-variable 'paragraph-separate)
  798. X  (setq paragraph-separate paragraph-start)
  799. X  (make-local-variable 'comment-start)
  800. X  (setq comment-start "%")
  801. X  (make-local-variable 'comment-start-skip)
  802. X  (setq comment-start-skip "[^\\]\\(\\(\\\\\\\\\\)*\\)%+ *")
  803. X  (make-local-variable 'comment-indent-hook)
  804. X  (setq comment-indent-hook 'TeX-comment-indent)
  805. X  (make-local-variable 'TeX-command)
  806. X  (make-local-variable 'TeX-trailer))
  807. X
  808. X(defun TeX-comment-indent ()
  809. X  (if (looking-at "%%%")
  810. X      (current-column)
  811. X    (skip-chars-backward " \t")
  812. X    (max (if (bolp) 0 (1+ (current-column)))
  813. X     comment-column)))
  814. X
  815. X(defun TeX-insert-quote (arg)
  816. X  "Insert ``, '' or \" according to preceding character.
  817. XWith prefix argument, always insert \" characters."
  818. X  (interactive "P")
  819. X  (if arg
  820. X      (let ((count (prefix-numeric-value arg)))
  821. X    (if (listp arg)
  822. X        (self-insert-command 1)    ;C-u always inserts just one
  823. X      (self-insert-command count)))
  824. X    (insert
  825. X     (cond
  826. X      ((or (bobp)
  827. X       (save-excursion
  828. X         (forward-char -1)
  829. X         (looking-at "[ \t\n]\\|\\s(")))
  830. X       "``")
  831. X      ((= (preceding-char) ?\\)
  832. X       ?\")
  833. X      (t "''")))))
  834. X
  835. X(defun validate-TeX-buffer ()
  836. X  "Check current buffer for paragraphs containing mismatched $'s.
  837. XAs each such paragraph is found, a mark is pushed at its beginning,
  838. Xand the location is displayed for a few seconds."
  839. X  (interactive)
  840. X  (let ((opoint (point)))
  841. X    (goto-char (point-max))
  842. X    ;; Does not use save-excursion
  843. X    ;; because we do not want to save the mark.
  844. X    (unwind-protect
  845. X    (while (and (not (input-pending-p)) (not (bobp)))
  846. X      (let ((end (point)))
  847. X        (search-backward "\n\n" nil 'move)
  848. X        (or (TeX-validate-paragraph (point) end)
  849. X        (progn
  850. X          (push-mark (point))
  851. X          (message "Mismatch found in pararaph starting here")
  852. X          (sit-for 4)))))
  853. X      (goto-char opoint))))
  854. X
  855. X(defun TeX-validate-paragraph (start end)
  856. X  (condition-case ()
  857. X      (save-excursion
  858. X    (save-restriction
  859. X      (narrow-to-region start end)
  860. X      (goto-char start)
  861. X      (forward-sexp (- end start))
  862. X      t))
  863. X    (error nil)))
  864. X
  865. X(defun TeX-terminate-paragraph (inhibit-validation)
  866. X  "Insert two newlines, breaking a paragraph for TeX.
  867. XCheck for mismatched braces/$'s in paragraph being terminated.
  868. XA prefix arg inhibits the checking."
  869. X  (interactive "P")
  870. X  (or inhibit-validation
  871. X      (TeX-validate-paragraph
  872. X       (save-excursion
  873. X     (search-backward "\n\n" nil 'move)
  874. X     (point))
  875. X       (point))
  876. X      (message "Paragraph being closed appears to contain a mismatch"))
  877. X  (insert "\n\n"))
  878. X
  879. X(defun TeX-insert-braces ()
  880. X  "Make a pair of braces and be poised to type inside of them."
  881. X  (interactive)
  882. X  (insert ?\{)
  883. X  (save-excursion
  884. X    (insert ?})))
  885. X
  886. X;;; Like TeX-insert-braces, but for LaTeX.
  887. X(defun TeX-close-LaTeX-block ()
  888. X  "Creates an \\end{...} to match \\begin{...} on the current line and
  889. Xputs point on the blank line between them."
  890. X  (interactive "*")
  891. X  (let ((fail-point (point)))
  892. X    (end-of-line)
  893. X    (if (re-search-backward "\\\\begin{\\([^}\n]*\\)}"
  894. X                (save-excursion (beginning-of-line) (point)) t)
  895. X    (let ((text (buffer-substring (match-beginning 1) (match-end 1)))
  896. X          (indentation (current-column)))
  897. X      (end-of-line)
  898. X      (delete-horizontal-space)
  899. X      (insert "\n\n")
  900. X      (indent-to indentation)
  901. X      (insert "\\end{" text "}")
  902. X      (forward-line -1))
  903. X      (goto-char fail-point)
  904. X      (ding))))
  905. X
  906. X;;; Invoking TeX in an inferior shell.
  907. X
  908. X;;; Why use a shell instead of running TeX directly?  Because if TeX
  909. X;;; gets stuck, the user can switch to the shell window and type at it.
  910. X
  911. X;;; The utility functions:
  912. X
  913. X(defun TeX-start-shell ()
  914. X  (require 'shell)
  915. X  (if (eq (process-status "TeX-shell") 'run) ()
  916. X  (save-excursion
  917. X    (let ((buffer (make-shell "TeX-shell" shell-file-name nil "-v")))
  918. X      (process-kill-without-query (get-buffer-process buffer))
  919. X      (set-buffer buffer)
  920. X      (setq TeX-shell-map (copy-keymap shell-mode-map))
  921. X      (TeX-define-common-keys TeX-shell-map)
  922. X      (use-local-map TeX-shell-map)))))
  923. X
  924. X(defun set-buffer-directory (buffer directory)
  925. X  "Set BUFFER's default directory to be DIRECTORY."
  926. X  (setq directory (file-name-as-directory (expand-file-name directory)))
  927. X  (if (not (file-directory-p directory))
  928. X      (error "%s is not a directory" directory)
  929. X    (save-excursion
  930. X      (set-buffer buffer)
  931. X      (setq default-directory directory))))
  932. X
  933. X;;; It's a kludge that we have to create a special buffer just 
  934. X;;; to write out the TeX-trailer.  It would nice if there were a
  935. X;;; function like write-region that would write literal strings.
  936. X
  937. X;;; write-region complains if the file is also a buffer. To overcome
  938. X;;; this, here is my version
  939. X(defun my-write-region (beg end file app)
  940. X"The region between BEGIN and END of the current buffer is written or
  941. Xappended to the FILE depending whether the fourth argument is nil or
  942. Xnon-nil (append in the latter case)."
  943. X    (call-process-region beg end shell-file-name nil nil nil
  944. X    "-F" "-c" (concat "cat " (if app ">>" ">") "\"" file "\""))
  945. X)
  946. X
  947. X(defun TeX-region (beg end)
  948. X  "Run TeX on the current region.  The region is filtered through the
  949. Xprogram given in (TeX-filter) to produce the temporary file (TeX-zap-file)
  950. Xin directory (TeX-directory). TeX is run in that directory. If the buffer has
  951. Xa header, it is written to the temporary file before the region. Also, the
  952. Xvalue of the TeX-trailer is appended to the file. They are NOT filtered through
  953. X(TeX-filter). The buffer's header is all lines between the string defined by
  954. XTeX-start-of-header and TeX-end-of-header inclusive."
  955. X  (interactive "r")
  956. X  (or TeX-zap-file (setq TeX-zap-file (make-temp-name "#tz")))
  957. X  (let* ((tex-out-file (concat TeX-zap-file ".tex"))
  958. X     (tex-out-buffer (get-file-buffer tex-out-file))
  959. X     (temp-buffer (get-buffer-create " TeX-Output-Buffer"))
  960. X     (zap-directory (expand-file-name TeX-directory))
  961. X         (local-tex-trailer TeX-trailer))
  962. X    (unwind-protect (save-excursion (save-restriction
  963. X    (widen)
  964. X    (goto-char (point-min))
  965. X    (forward-line 100)
  966. X    (let ((search-end (point))
  967. X          (hbeg (point-min)) (hend (point-min))
  968. X          (default-directory zap-directory))
  969. X      (goto-char (point-min))
  970. X      ;; Initialize the temp file with either the header or nothing
  971. X      (if (search-forward TeX-start-of-header search-end t)
  972. X          (progn
  973. X        (forward-line -1)
  974. X        (setq hbeg (point))    ;mark beginning of header
  975. X        (if (search-forward TeX-end-of-header nil t)
  976. X            (progn (forward-line 1)
  977. X               (setq hend (min beg (point))));mark end of header
  978. X          (setq hbeg (point-min))))) ;no header
  979. X      (my-write-region (min hbeg beg) hend tex-out-file nil))
  980. X         (message "Preprocessing...")
  981. X         (narrow-to-region beg end)
  982. X         (sit-for 0)
  983. X         (save-excursion  (set-buffer temp-buffer)  (erase-buffer))
  984. X         (if TeX-filter
  985. X           (apply 'call-process-region
  986. X             (append (list beg end TeX-filter nil temp-buffer nil)
  987. X                     TeX-filter-args
  988. X                     (list (concat zap-directory tex-out-file))))
  989. X           (my-write-region beg end (concat zap-directory tex-out-file) t))
  990. X         (message "Done...") (sit-for 0)
  991. X    )))
  992. X    (if (save-excursion (set-buffer temp-buffer)
  993. X                (beginning-of-file) (eobp))
  994. X        (progn
  995. X           (save-excursion
  996. X             (set-buffer temp-buffer)
  997. X             (set-buffer-directory temp-buffer zap-directory)
  998. X             (insert-string "\n")
  999. X             (if local-tex-trailer (insert-string local-tex-trailer))
  1000. X             (my-write-region (point-min) (point-max) tex-out-file t))
  1001. X           (pop-to-TeX-shell zap-directory tex-out-file)
  1002. X         )
  1003. X;;; error during preprocessing, show the error messages ...
  1004. X      (let ((buffer (current-buffer))) 
  1005. X        (pop-to-buffer temp-buffer)
  1006. X        (pop-to-buffer buffer))
  1007. X    )
  1008. X))
  1009. X
  1010. X(defun pop-to-TeX-shell (zap-directory tex-out-file)
  1011. X   (if (get-buffer "*TeX-shell*") (TeX-kill-job))
  1012. X   (TeX-start-shell)
  1013. X   (set-buffer-directory "*TeX-shell*" zap-directory)
  1014. X   (send-string "TeX-shell" (concat TeX-shell-cd-command " "
  1015. X                     zap-directory "\n"))
  1016. X   (send-string "TeX-shell" (concat TeX-command " \""
  1017. X                     tex-out-file "\"\n"))
  1018. X   (TeX-recenter-output-buffer 0)
  1019. X)
  1020. X
  1021. X(defun TeX-buffer ()
  1022. X  "Run TeX on current buffer.  See \\[TeX-region] for more information."
  1023. X  (interactive)
  1024. X  (TeX-region (point-min) (point-max)))
  1025. X
  1026. X(defun TeX-kill-job ()
  1027. X  "Kill the currently running TeX job."
  1028. X  (interactive)
  1029. X  (if (process-status "TeX-shell")      ; not nil if the process exists
  1030. X      (quit-process "TeX-shell" t)))
  1031. X
  1032. X(defun TeX-recenter-output-buffer (linenum)
  1033. X  "Redisplay buffer of TeX job output so that most recent output can be seen.
  1034. XThe last line of the buffer is displayed on
  1035. Xline LINE of the window, or centered if LINE is nil."
  1036. X  (interactive "P")
  1037. X  (let ((tex-shell (get-buffer "*TeX-shell*"))
  1038. X    (old-buffer (current-buffer)))
  1039. X    (if (null tex-shell)
  1040. X    (message "No TeX output buffer")
  1041. X      (pop-to-buffer tex-shell)
  1042. X      (bury-buffer tex-shell)
  1043. X      (goto-char (point-max))
  1044. X      (recenter (if linenum
  1045. X            (prefix-numeric-value linenum)
  1046. X          (/ (window-height) 2)))
  1047. X      (pop-to-buffer old-buffer)
  1048. X      )))
  1049. X
  1050. X(defun TeX-print ()
  1051. X  "Print the .dvi file made by \\[TeX-region] or \\[TeX-buffer].
  1052. XRuns the shell command defined by TeX-dvi-print-command."
  1053. X  (interactive)
  1054. X  (send-string "TeX-shell"
  1055. X           (concat TeX-dvi-print-command " \"" TeX-zap-file ".dvi\"\n"))
  1056. X  (TeX-recenter-output-buffer nil))
  1057. X
  1058. X(defun TeX-view-dvi ()
  1059. X  "Shows the .dvi file on the screen bu the shell command defined 
  1060. Xby TeX-show-dvi-command."
  1061. X  (interactive)
  1062. X  (send-string "TeX-shell"
  1063. X           (concat TeX-show-dvi-command " \"" TeX-zap-file ".dvi\"\n"))
  1064. X  (TeX-recenter-output-buffer nil))
  1065. X
  1066. X(defun TeX-show-print-queue ()
  1067. X  "Show the print queue that \\[TeX-print] put your job on.
  1068. XRuns the shell command defined by TeX-show-queue-command."
  1069. X  (interactive)
  1070. X  (if (not (get-buffer "*TeX-shell*"))
  1071. X      (TeX-start-shell))
  1072. X  (send-string "TeX-shell" (concat TeX-show-queue-command "\n"))
  1073. X  (TeX-recenter-output-buffer nil))
  1074. X
  1075. END_OF_FILE
  1076. if test 20255 -ne `wc -c <'tex-mode.el'`; then
  1077.     echo shar: \"'tex-mode.el'\" unpacked with wrong size!
  1078. fi
  1079. # end of 'tex-mode.el'
  1080. fi
  1081. echo shar: End of archive 1 \(of 2\).
  1082. cp /dev/null ark1isdone
  1083. MISSING=""
  1084. for I in 1 2 ; do
  1085.     if test ! -f ark${I}isdone ; then
  1086.     MISSING="${MISSING} ${I}"
  1087.     fi
  1088. done
  1089. if test "${MISSING}" = "" ; then
  1090.     echo You have unpacked both archives.
  1091.     rm -f ark[1-9]isdone
  1092. else
  1093.     echo You still need to unpack the following archives:
  1094.     echo "        " ${MISSING}
  1095. fi
  1096. ##  End of shell archive.
  1097. exit 0
  1098.